;_____________________________________________________________
;Hero Mode Files
;This will make it so that you can create two different file
;types by pressing the backspace button during name selection.
;The theme of the file select will change depending on
;currently selected file type.
;Hero Mode uses the debug file.
;_____________________________________________________________

;T3 = Current File in loop (1 indexed)
;T8 = File Mode (1 = Disk)
;T6, T7, T8, T9
.org 0x803FBFFC
	LW		A2, 0x02C0(T1)		;Already there
	LUI		T9, 0x8023			;T9 = 0x80230000
	LHU		T6, 0xEA58(T9)		;T6 = Currently selected file
	ADDIU	T6, T6, 0x0001		;T6 = Currently selected file + 0x1
	BNE		T6, T3, 0x803FC128	;Branch if it is currently NOT looping through selected file
	LHU		T6, 0xEA5E(T9)		;T6 = Current Menu
	SLTI	T7, T6, 0x0003		;T7 is set if you're in main menu
	BNE		T7, R0, continue	;Continue if you're in main menu
	ADDIU	T7, R0, 0x0004		;T7 = 0x0004
	BEQ		T6, T7, continue	;Continue if you're in copy which file
	ADDIU	T7, R0, 0x0015		;T7 = 0x0015
	BNE		T6, T7, 0x803FC128	;End if you're not in erase which file
	continue:
	LUI		T6, 0x8040			;T6 = 0x80400000
	BNEL	T8, R0, hero		;Branch Likely if hero mode
	ADDIU	T6, T6, 0x6			;T6 = 0x80400006
	LUI		T8, 0x8012			;T8 = 0x80120000
	ADDIU	T7, R0, 0x0003		;T7 = 0x03
	SB		T7, 0xFCB2(T8)		;Set skybox to 0x3
	ADDIU	T7, R0, 0x009B		;T7 = 0x9B
	SH		T7, 0xEAC2(T9)		;Cursor Red = T7
	ADDIU	T7, R0, 0xFFFF		;T7 = 0xFFFFFFFF
	BEQ		R0, R0, skip		
	SW		T7, 0xEAC4(T9)		;Cursor Green & Blue = T7
	hero:
	LUI		T8, 0x8012			;T8 = 0x80120000
	ADDIU	T7, R0, 0x0007		;T7 = 0x07
	SB		T7, 0xFCB2(T8)		;Set skybox to 0x7
	ADDIU	T7, R0, 0x00F0		;T7 = 0xF0
	SH		T7, 0xEAC2(T9)		;Cursor Red = T7
	SH		T7, 0xEAC4(T9)		;Cursor Green = T7
	ADDIU	T7, R0, 0x00D0		;T7 = 0xD0
	SH		T7, 0xEAC6(T9)		;Cursor Blue = T7
	skip:
	LHU		T7, 0xFDBC(T6)		;T7 = Red
	SH		T7, 0xEA88(T9)		;Background Red = T7
	LHU		T7, 0xFDBE(T6)		;T7 = Green
	SH		T7, 0xEA8A(T9)		;Background Green = T7
	LHU		T7, 0xFDC0(T6)		;T7 = Blue
	SH		T7, 0xEA8C(T9)		;Background Blue = T7
	NOP
	NOP
	NOP
	NOP
	NOP
	BEQ		R0, R0, 0x803FC128
	NOP
	
.org 0x803FC248
	BEQ		R0, R0, 0x803FC26C	;remove disk attachment
	
.org 0x803FC2A0
	BEQ		R0, R0, 0x803FC2B8	;make file name color normal
	
.org 0x803F8DC4
	NOP							;Make file selectable
	
.org 0x803FBD88
	BEQ		R0, R0, 0x803FBD98	;Fix file color when chosen

;----------------
;File Creation 
;----------------
	
.org 0x803F614C
	BNEL	T7, R0, setColor	;Branch to color update function instead
	
.org 0x803F616C					;Set backspace to swap file type
	LH		T7, 0x4A48(T0)		;T7 = File Type
	BEQL	T7, R0, hmode		;If file type is normal, set to hero mode
	ADDIU	T7, R0, 0x0001		;Set file type to hero mode
	ADDU	T7, R0, R0			;Set file type to normal mode
	hmode:
	BEQ		R0, R0, 0x803F6494	;Continue
	SH		T7, 0x4A48(T0)		;Store file type
	NOP
	setColor:
	LUI		T9, 0x8023			;T6 = 0x80230000
	LUI		T6, 0x8040			;T6 = 0x80400000
	LH		T7, 0x4A48(T0)		;T7 = File Type
	BNEL	T7, R0, hclr		;Branch if file type is Hero Mode
	ADDIU	T6, T6, 0x6			;T6 = 0x80400006
	ADDIU	T7, R0, 0x0003		;T7 = 0x03
	SB		T7, 0x0392(S3)		;Set skybox to 0x3
	ADDIU	T7, R0, 0x009B		;T7 = 0x9B
	SH		T7, 0xEAC2(T9)		;Cursor Red = T7
	ADDIU	T7, R0, 0xFFFF		;T7 = 0xFFFFFFFF
	BEQ		R0, R0, skp		
	SW		T7, 0xEAC4(T9)		;Cursor Green & Blue = T7
	hclr:
	ADDIU	T7, R0, 0x0007		;T7 = 0x07
	SB		T7, 0x0392(S3)		;Set skybox to 0x7
	ADDIU	T7, R0, 0x00F0		;T7 = 0xF0
	SH		T7, 0xEAC2(T9)		;Cursor Red = T7
	SH		T7, 0xEAC4(T9)		;Cursor Green = T7
	ADDIU	T7, R0, 0x00D0		;T7 = 0xD0
	SH		T7, 0xEAC6(T9)		;Cursor Blue = T7
	skp:
	LHU		T7, 0xFDBC(T6)		;T7 = Red
	SH		T7, 0xEA88(T9)		;Background Red = T7
	LHU		T7, 0xFDBE(T6)		;T7 = Green
	SH		T7, 0xEA8A(T9)		;Background Green = T7
	LHU		T7, 0xFDC0(T6)		;T7 = Blue
	SH		T7, 0xEA8C(T9)		;Background Blue = T7
	BEQ		R0, R0, 0x803F6494	;Continue
	NOP
	
.org 0x803F6694
	SH		R0, 0x4A48(A1)		;Reset File Type when entering File Creation
	
.org 0x803FE7C8
	LUI		AT, 0xFFFF			;A-Decide*B-Cancel Red & Green
.org 0x803FE7DC
	ORI		AT, AT, 0xFF00		;A-Decide*B-Cancel Blue